﻿#define _CRT_SECURE_NO_WARNINGS 1
#include"Set.h"
#include"Map.h"
#include<iostream>
#include<vector>
#include<map>

using namespace std;

//重大报错：
// const版本的begin和end没在后面加const
//	typedef iterator时没有设为public：
// operator++ 代码搞错了
// begin()代码实现错了

namespace gy
{
	void test1()
	{
		Map<int, int> t;
		// 常规的测试⽤例
		//int a[] = { 16, 3, 7, 11, 9, 26, 18, 14, 15 };
		// 特殊的带有双旋场景的测试⽤例
		int a[] = { 4, 2, 6, 1, 3, 5, 15, 7, 16, 14 };
		for (auto e : a)
		{
			t.Insert({ e, e });
			//t.Insert(e);
		} 
		
		Map<int, int>::iterator it = t.end();
		
		while (it != t.begin())
		{
			--it;

			cout << it->first << "：" << it->second << endl;
			//cout << *it << endl;
		}
		
	}

	void test2()
	{
		const int N = 100000;
		vector<int> v;
		v.reserve(N);
		srand(time(0));
		for (size_t i = 0; i < N; i++)
		{
			v.push_back(rand() + i);
		}
		size_t begin2 = clock();
		Map<int, int> t;
		for (auto e : v)
		{
			t.Insert(make_pair(e, e));
		}
		size_t end2 = clock();
		cout << "Insert:" << end2 - begin2 << endl;
		//cout << t.IsBalanceTree() << endl;
		cout << "Height:" << t.Height() << endl;
		cout << "Size:" << t.Size() << endl;
		size_t begin1 = clock();
		// 确定在的值
		/*for (auto e : v)
		{
		t.Find(e);
		}*/
		// 随机值
		for (size_t i = 0; i < N; i++)
		{
			t.Find((rand() + i));
		}size_t end1 = clock();
		cout << "Find:" << end1 - begin1 << endl;
	}

	void test3()
	{
		// 利⽤find和iterator修改功能，统计⽔果出现的次数
		string arr[] = { "苹果", "西瓜", "苹果", "西瓜", "苹果", "苹果", "西瓜",
		"苹果", "香蕉", "苹果", "香蕉" };
		Map<string, int> countMap;
		for (const auto& str : arr)
		{
			countMap[str]++;
		}
		for (const auto & e : countMap)
		{
			cout << e.first << ":" << e.second << endl;
		} 
		cout << endl;
		
	}
}


int main()
{
	gy::test3();
	return 0;
}